package com.jbit.hxy.controller;

import com.jbit.hxy.common.Result;
import com.jbit.hxy.model.dto.CategoryFromDTO;
import com.jbit.hxy.model.dto.CategoryQueryDTO;
import com.jbit.hxy.model.po.CategoryDish;
import com.jbit.hxy.service.menu.WxCategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
@RequiredArgsConstructor
@Tag(name = "菜单管理")
public class WxCategoryController {
    private final WxCategoryService wxCategoryService;
    @PostMapping("/list")
    @Operation(summary = "获取菜单列表",description = "获取菜单列表")
    public Result list(@RequestBody CategoryQueryDTO categoryQueryDTO){
        return wxCategoryService.getCategory(categoryQueryDTO);
    }
    @PostMapping("/add")
    @Operation(summary = "添加菜单",description = "添加菜单")
    public Result add(@RequestBody CategoryFromDTO categoryFromDTO){
        return wxCategoryService.addCategory(categoryFromDTO);

    }
    @PostMapping("/update")
    @Operation(summary = "更新菜单",description = "更新菜单")
    public Result update(@RequestBody CategoryFromDTO categoryFromDTO){
        return wxCategoryService.updateCategory(categoryFromDTO);
    }

    @GetMapping("/delete")
    @Operation(summary = "删除菜单",description = "删除菜单")
    public Result delete(@RequestParam("id") Integer id){
        return wxCategoryService.deleteCategory(id);
    }
    @GetMapping("/getCategory")
    @Operation(summary = "获取菜单",description = "获取菜单")
    public Result getCategory(){
        return wxCategoryService.getCategorys();

    }
    @PostMapping("/saveDishesByCateId")
    @Operation(summary = "给分类保存菜品",description = "给分类保存菜品")
    public Result saveDishesByCateId(@RequestBody List<CategoryDish> list) {
        return wxCategoryService.saveDishesByCateId(list);
    }

    @GetMapping("/deleteAll")
    @Operation(summary = "根据cateId删除所有菜品",description = "根据cateId删除所有菜品")
    public Result deleteAll(@RequestParam("cateId") Integer cateId){
        return wxCategoryService.deleteAll(cateId);
    }


}
